'use strict';
$(document).ready(function () {
  var indexPage = function () {
    var methods = {
      // 轮盘动画
      initAnimation: function initAnimation() {
        $('.lpImg').addClass('lpAnimation');
        setTimeout(function () {
          $(".money>img").css('opacity', '1').css('width', '100%').css('height', '100%');
        }, 1000);
      },
      // 下载
      download: function download() {
        if (/i(os|phone|pad)/i.test(navigator.userAgent)) {
          // ios
          window.location.href = 'https://itunes.apple.com/cn/app/%E6%9C%89%E9%92%B1%E8%AE%B0-%E8%AE%B0%E8%B4%A6app/id1434811529?mt=8';
        } else if (/android/i.test(navigator.userAgent)) {
          // 安卓
        }
      }
    };
    var o = {
      init: function init() {
        methods.initAnimation();
      }
    };
    return o;
  }();
  indexPage.init();

  var flag = false;
  var baseUrl = "http://res.txingdai.com";

  function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); // 构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg); // 匹配目标参数
        if (r != null)
            return r[2];
        return null; // 返回参数值
  }

  var tip = false;
  if (tip == false) {
    $(".btn").click(function () {
      tip = true;
      var channel = getUrlParam('c');

      var mobile = $("#tel").val();
      if (mobile == '') {
        alert('请输入您的手机号码');
        tip = false;
        return false;
      }

      $.ajax({
        type: "POST",
        dataType: "json",
        data: {
          phone: mobile,
          boundleId: "com.tengxin.youqianji",
          key: channel
        },
        url: baseUrl + "/url/register_app",
        success: function (res) {
          tip = false;
          if(res.code === 10302){
            window.location.href = res.data;
            return false;
          }else if (res.code !== 10200) {
            alert(res.msg);
            return false;
          }
          if (/i(os|phone|pad)/i.test(navigator.userAgent)) {
            // ios
            window.location.href = 'https://itunes.apple.com/cn/app/%E6%9C%89%E9%92%B1%E8%AE%B0-%E8%AE%B0%E8%B4%A6app/id1434811529?mt=8';
            return false;
          } else if (/android/i.test(navigator.userAgent)) {
            // 安卓
            window.location.href = 'http://p64nzai09.bkt.clouddn.com/apk/youqianji/1.0/app-release.apk';
            window.event.returnValue = false;
          }
        }
      });
    });
  }
});
